package filmsystem.example.film.controllers;

import filmsystem.example.film.dao.CinemaRepository;
import filmsystem.example.film.entities.Cinema;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("cinema")
public class CinemaController {

    @Autowired
    CinemaRepository cinemaRepository;

    @GetMapping("/new")
    public String displayCinemaForm(Model model){

        Cinema aCinema = new Cinema();
        model.addAttribute("cinema",aCinema);
        return "admin/new-cinema";
    }

    @PostMapping("/save")
    public String createCinema(Model model,Cinema cinema){

        cinemaRepository.save(cinema);
        return "redirect:/cinema/new";
    }
}
